/* eslint-disable no-param-reassign */
/* eslint-disable no-return-await */
/* eslint-disable import/no-extraneous-dependencies */
import axios from 'axios';
import store from 'storejs';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';


const strategy = {
  development: 'http://121.41.218.83:3000',
};


const service = axios.create({
  baseURL: strategy[process.env.NODE_ENV],
  timeout: 2500,
  withCredentials: true,
});

// 请求拦截
service.interceptors.request.use((config) => {
  NProgress.start();
  // eslint-disable-next-line no-console
  const user = store.get('user');
  if (user && user.cookie) {
    // config.url = `${config.url}?timestamp=${Date.now()}&cookie=${user.cookie}`;
    config.params.cookie = user.cookie;
    config.params.timestamp = Date.now();
  }
  return config;
});

service.interceptors.response.use(response =>
  // eslint-disable-next-line no-console
  // console.log(response);
  response,
);


const api = {
  // 获取推荐歌单列表
  async getRecommendList(params) {
    return await service.get('/personalized', { params });
  },
  // 推荐艺人列表
  async getArtistList(params) {
    return await service.get('/artist/list', { params });
  },
  // 新专辑速递
  async getNewAlbum(params) {
    return await service.get('/album/new', { params });
  },
  // 排行榜
  async getToplist(params) {
    return await service.get('/toplist/detail', { params });
  },
  // 获取ForYou的图片
  // async getForYou(params) {
  //   return await service.get('http://p3.music.126.net/wu2L5KJqvqUl5Ru0khGr2A==/109951165950923599.jpg', { params });
  // },
  // 获取手机号登录信息
  async loginPhone(params) {
    return await service.get('/login/cellphone', { params });
  },
  // 获取当前用户登录状态接口
  async loginStatus(params) {
    return await service.get('/login/status', { params });
  },
  // 邮箱登录接口
  async loginEmail(params) {
    return await service.get('/login', { params });
  },
  // 获取搜索列表的用户信息
  async getSearchUser(params) {
    return await service.get('/search', { params });
  },
  // 获取歌手详细信息
  async getSongDetail(params) {
    return await service.get('/song/detail', { params });
  },
  // 获取二维码的key
  async qrKey() {
    return await service.get('/login/qr/key');
  },
  // 获取二维码图片
  async qrInfo(params) {
    return await service.get('/login/qr/create', { params });
  },
  // 获取二维码扫码后的登录后的个人信息
  async checkQrStatus(params) {
    return await service.get('/login/qr/check', { params });
  },
  // 首页轮播
  async getBanner(params) {
    return await service.get('/banner', { params });
  },
  // 登出接口
  async loginOut(params) {
    return await service.get('/logout', { params });
  },
  // 每日推荐接口
  async everyRecommend(params) {
    return await service.get('/recommend/songs', { params });
  },
  // 发现页全部
  async exploreItemAll(params) {
    return await service.get('/top/playlist', { params });
  },
  // 发现页精品歌单
  async highquality(params) {
    return await service.get('/top/playlist/highquality', { params });
  },
  // 发现页排行榜
  async toplist(params) {
    return await service.get('/toplist', { params });
  },
  // 发现页item跳转后的播放列表
  async playlistDetail(params) {
    return await service.get('/playlist/detail', { params });
  },
  // MV的相关视频
  async simiMv(params) {
    return await service.get('/simi/mv', { params });
  },
  // 详细的mv信息
  async mvDetail(params) {
    return await service.get('/mv/detail', { params });
  },
  // this.$mvSublist({
  //   cookie: store.get('user').cookie,
  // }).then((res) => {
  //   console.log(res);
  // }).catch((err) => {
  //   console.log(err);
  // });
  async mvSublist(params) {
    return await service.get('/mv/sublist', { params });
  },
  // 获取用户收藏歌曲
  async likeList(params) {
    return await service.get('/likelist', { params });
  },
  // 获取用户收藏歌曲歌词
  async musciLyric(params) {
    return await service.get('/lyric', { params });
  },
  // 获取用户全部歌单
  async userPlayList(params) {
    return await service.get('/user/playlist', { params });
  },
  // 获取用户收藏专辑
  async albumSublist(params) {
    return await service.get('/album/sublist', { params });
  },
  async artistSublist(params) {
    return await service.get('/artist/sublist', { params });
  },
  async mvUrl(params) {
    return await service.get('/mv/url', { params });
  },
};


export default api;
